package com.dimao.certificate_build_service.handle;

public class Result {
    private Throwable error;
    private Boolean succeed;

    public Result(boolean succeed, Throwable error){
        this.succeed = succeed;
        this.error = error;
    }

    @Override
    public boolean equals(Object obj) {
        Result result = (Result)obj;
        return (succeed == result.succeed) && (nullEquals(result) || (error.equals(result.error)));
    }

    public boolean succeeded(){
        return succeed;
    }

    public boolean failed(){
        return !succeed;
    }

    public Throwable cause(){
        return error;
    }

    private boolean nullEquals(Result result){
        return (error == null) && (result.error == null);
    }
}
